//
//  WBHomeViewController.swift
//  XLWebo
//
//  Created by 陈晓龙 on 17/2/15.
//  Copyright © 2017年 陈晓龙. All rights reserved.
//

import UIKit
private let cellId = "cellId"

class WBHomeViewController: BaseViewController {

    lazy var statusList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        
    
        
    }
    
    //重写 加载数据
    override func loadData() {
        // 模拟演示加载数据
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+2) {
            print("jiazai")
            for i in 0..<20 {
                if self.isPullup {
                    self.statusList.append("上拉\(i)")
                }else{
                    self.statusList.insert(i.description, at: 0)
                }
                
            }
            self.refreshControl?.endRefreshing()
            //恢复上拉刷新的标志
            self.isPullup = false
            self.tableView?.reloadData()
        }
        
        
    }
    
//end
}

extension WBHomeViewController{
 
    override func setupTableView() {
        super.setupTableView()
        //自定义
        navItem.leftBarButtonItem = UIBarButtonItem(title: "添加盆友", fontSize: 16, target: self, action: #selector(addFriend), isBack: false)
    }
    
    func addFriend()  {
        print("#function")
        let vc = AddFrientController()
        
        navigationController?.pushViewController(vc, animated: true )
        
    }
}


extension WBHomeViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: cellId)
        if cell == nil {
            cell =  UITableViewCell(style: .default, reuseIdentifier: cellId)
        }
        cell?.textLabel?.text = statusList[indexPath.row]
    return cell!
    }
}

